package cn.webestar.scms.user.api.dto.Config;

import cn.webestar.scms.commons.api.SimpleBody;
import cn.webestar.scms.user.entity.Config;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.util.StringUtils;

import java.util.Date;

@Data
@Schema(description = "ConfigSimpleDTO")
public class ConfigSimpleDTO extends SimpleBody {

    @Schema(description = "租户id")
    private Long cid;

    @Schema(description = "父键")
    private String pcode;

    @Schema(description = "键")
    private String code;

    @Schema(description = "值")
    private String val;

    @Schema(description = "标题")
    private String title;

    @Schema(description = "备注")
    private String remark;

    @Schema(description = "更新人")
    private Long updater;

    @Schema(description = "更新时间")
    private Date updateTime;

    @Override
    public LambdaQueryWrapper<Config> toQueryWapper() {
        LambdaQueryWrapper<Config> queryWrapper = new LambdaQueryWrapper<>();
        if (cid!=null) {
            queryWrapper.eq(Config::getCid, cid);
        }
        if (StringUtils.hasText(pcode)) {
            queryWrapper.eq(Config::getPcode, pcode);
        }
        if (StringUtils.hasText(code)) {
            queryWrapper.eq(Config::getCode, code);
        }
        if (StringUtils.hasText(val)) {
            queryWrapper.eq(Config::getVal, val);
        }
        if (StringUtils.hasText(title)) {
            queryWrapper.eq(Config::getTitle, title);
        }
        if (StringUtils.hasText(remark)) {
            queryWrapper.eq(Config::getRemark, remark);
        }
        if (updater!=null) {
            queryWrapper.eq(Config::getUpdater, updater);
        }
        if (updateTime!=null) {
            queryWrapper.eq(Config::getUpdateTime, updateTime);
        }
        return queryWrapper;
    }

}
